package com.linkage.yninterface.db;

/**
 * <p>Title: yninterface</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: linkage</p>
 *
 * @author weibo
 * @version 1.0
 */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mchange.v2.c3p0.ConnectionTester;



public class testOraDBConnect  implements ConnectionTester {
	private static final Logger log = LoggerFactory
			.getLogger(testOraDBConnect.class);
	public testOraDBConnect() {

	}
	public int activeCheckConnection(Connection connection){
		String sql="select 1 from dual";
		//    String sql="select 1 from xxx";

		PreparedStatement ps=null;
		try {
			ps=connection.prepareStatement(sql);
			ps.execute();

		}
		catch (SQLException ex) {
			ex.printStackTrace();
			log.error("[" + (new java.util.Date())
					+ "] activeCheckConnection is false");
			return CONNECTION_IS_INVALID;
		}finally{
			if (ps != null) {
				try {
					ps.close();
				}
				catch (SQLException ex1) {
					log.error("activeCheckConnection close ps error");
					ex1.printStackTrace();
				}
			}

		}
		return CONNECTION_IS_OKAY;
	}
	public int statusOnException(Connection connection, Throwable throwable){
		log.error(".>>>>>>statusOnException.CONNECTION_IS_INVALID");
		//     return CONNECTION_IS_OKAY;
		return CONNECTION_IS_INVALID;
	}




}
